package com.lanou.springbootoracle.controller;

import com.lanou.springbootoracle.pojo.Dept;
import com.lanou.springbootoracle.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.annotation.MultipartConfig;
import java.io.File;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("dept")
@MultipartConfig
public class DeptController {
    @Autowired
    private DeptService deptService;
    @RequestMapping("findAll")
    public List<Dept> findAll(){
        return deptService.findAll();
    }

    @RequestMapping("findOne")
    public Dept findOne(Integer deptno){
        return deptService.findById(deptno);
    }

    @RequestMapping("save")
    public Boolean save(Dept dept, MultipartFile multipartFile){
        try {
            multipartFile.transferTo(new File("D:\\IdeaProjects\\springbootoracle\\src\\main\\resources\\static\\upload\\"+multipartFile.getOriginalFilename()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        dept.setImgpath("upload/"+multipartFile.getOriginalFilename());
        deptService.save(dept);
        return true;
    }
    @RequestMapping("update")
    public int update(Dept dept){
        int i = deptService.update(dept);
        return i;
    }

    @RequestMapping("delete")
    public int delete(Integer deptno){
        int i = deptService.delete(deptno);
        return i;
    }
}
